import _ from 'lodash';
import { firewallRequest } from '@core/utils/request';

export interface ApplicationSummary {
  name: string,
  id: string,
}

export default class Application {
  private static _list: Array<ApplicationSummary> = [];

  static fetchSummaryList = () => {
    return firewallRequest.get<void, Array<ApplicationSummary>>('/ctcloud/vfw/v1_app_queryAll');
  };

  static getSummaryList = async () => {
    if (_.isEmpty(Application._list)) {
      Application._list = await Application.fetchSummaryList();
    }
    return Application._list;
  };

  static getOneById = (id: string) => {
    return Application._list.find((app) => app.id.toString() === id);
  };
}
